//
// Created by wxd on 2025/9/11.
//

#pragma once

#ifndef LIGHT_H
#define LIGHT_H

#include "ILight.h"
#include <glm/glm.hpp>
#include <string>
#include "../global/generator_id.h"

// 光源抽象基类，提供通用实现
class Light : public ILight {
public:
    ~Light() override = default;

    // ILight 接口实现
    glm::vec3 getColor() const override { return mColor; }
    glm::vec3 getIntensity() const override { return mIntensity; }
    std::string getName() const override { return mName; }
    std::string getTraceId() const override { return mTraceId; }
    bool isEnabled() const override { return mEnabled; }
    void setEnabled(bool enabled) override { mEnabled = enabled; }

    void update(float deltaTime) override { /* 默认空实现 */ }

    // 设置颜色
    virtual void setColor(const glm::vec3& color) { mColor = color; }

    // 设置强度
    virtual void setIntensity(glm::vec3& intensity) { mIntensity = intensity; }

    // 设置名称
    virtual void setName(const std::string& name) { mName = name; }

    // 设置traceId
    virtual void setTraceId(const std::string& traceId) { mTraceId = traceId; }

    // 设置光源类型
    virtual void setType(const LightType& type) { mLightType = type; }

    // 设置是否使用该光源
    virtual void setEnable(const bool enable) { mEnabled = enable; }

protected:
    Light() {
        mTraceId = IDGenerator::getInstance().generateString(IDPrefix::LIGHT);
    }

    // 保护构造函数，只能由子类调用
    Light(const LightType& type, const glm::vec3& color, const glm::vec3& intensity, const std::string& name)
        : mLightType(type), mColor(color), mIntensity(intensity), mName(name), mEnabled(true) {
        mTraceId = IDGenerator::getInstance().generateString(IDPrefix::LIGHT);
    }

    std::string mTraceId;
    LightType mLightType { LightType::NONE };
    glm::vec3 mColor { glm::vec3(1.f) };
    glm::vec3 mIntensity { glm::vec3(1.f) };
    std::string mName { "Light" };
    bool mEnabled { true };
};

#endif //LIGHT_H
